package test.qartz;

import javax.annotation.Resource;

import org.springframework.scheduling.quartz.CronTriggerFactoryBean;

public class InitializingCronTrigger extends CronTriggerFactoryBean {

	private static final long serialVersionUID = 703059898656706820L;

	@Resource
	private ScheduleInfoManager scheduleInfoManager;
	
    // 设值注入，通过setter方法传入被调用者的实例scheduleInfoManager
	public void setScheduleInfoManager(ScheduleInfoManager scheduleInfoManager){
		this.scheduleInfoManager = scheduleInfoManager;
		// 因为在getCronExpressionFromDB使用到了scheduleInfoManager，所以
		// 必须上一行代码设置scheduleInfoManager后进行getCronExpressionFromDB
		String cronExpression = getCronExpressionFromDB ();
		// 因为extends CronTriggerBean ，此处调用父类方法初始化cronExpression
		setCronExpression(cronExpression);
	}
	
	private String getCronExpressionFromDB(){
//		String sql="from ScheduleInfo scheduleInfo where 1=1 ";
//		sql=sql+" and scheduleInfo.infoId = '"+"1" + "'";
//		List scheduleList = scheduleInfoManager.queryScheduleInListBySql(sql);
//		ScheduleInfo scheduleInfo = (ScheduleInfo)scheduleList.get(0);
		String dbCronExpression = "";//scheduleInfo.getCronExpression();
		return dbCronExpression;
	}
}